package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.BannerMall;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description: 集团下发banner给商场
 * @Author: liucancan
 * @Date: 2018/9/29
 */
public interface BannerMallMapper extends MyMapper<BannerMall> {

    // 根据banner_id查询并根据mall_code和sort分组
    @Select("SELECT * FROM `t_mall_banner` tmb where tmb.banner_id = #{bannerId} GROUP BY tmb.banner_order,tmb.mall_code")
    List<BannerMall> findBannerMall(@Param("bannerId") int bannerId);

    @Delete("delete from t_mall_banner where id in (select id from (select tmb.id from t_mall_banner tmb LEFT JOIN t_banner tb on tb.id = tmb.banner_id where 1 = 1 and tmb.mall_code = #{mallCode} and tmb.banner_order = #{sort} and tb.status = 1 and tmb.banner_id != #{bannerId}) t)")
    void deleteBannerMallByMallCodeAndSort(@Param("mallCode") String mallCode, @Param("sort") int sort, @Param("bannerId") int bannerId);
}
